import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:mokeng/models/entities.dart';
import 'package:mokeng/utils/utils.dart';
import 'package:mokeng/values/values.dart';
import 'package:mokeng/widgets/get_view_keep_alive.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'logic.dart';

class MatchView extends GetViewKeepAlive<MatchController> {
  MatchView({super.key}) {
    Get.put(MatchController());
  }

  Widget buildItem(MatchInfo info) {
    return InkWell(
      onTap: () {
        Get.toNamed("/match/detail", arguments: info);
      },
      child: Stack(children: [
        SizedBox(
          width: 1.sw,
          height: 212.h,
        ),
        Positioned(
          top: 43.h,
          left: 14.w,
          right: 14.w,
          height: 169.h,
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 10.h),
            // 顶部系统栏 44px
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: 10.radius,
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.end,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  info.name,
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    color: Colors.black,
                    fontSize: 14.sp,
                  ),
                ),
                7.hGap,
                Text(
                  info.time,
                  style: TextStyle(
                    color: Colors.black.withOpacity(0.3),
                    fontSize: 10.sp,
                  ),
                ),
                7.hGap,
                Row(
                  children: [
                    Text(
                      "距离截稿还有",
                      style: TextStyle(
                        color: Colors.black.withOpacity(0.3),
                        fontSize: 10.sp,
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 2.w),
                      child: Text(
                        info.leftTime,
                        style: TextStyle(
                          color: Colors.orange,
                          fontSize: 14.sp,
                          fontFamily: "Akrobat",
                        ),
                      ),
                    ),
                    Text(
                      "天",
                      style: TextStyle(
                        color: Colors.black.withOpacity(0.3),
                        fontSize: 10.sp,
                      ),
                    ),
                    const Spacer(),
                    Image.asset(
                      "assets/images/ic_renshu.png",
                      width: 14.w,
                      height: 14.w,
                    ),
                    Text(
                      info.count1.toString(),
                      style: TextStyle(
                        color: Colors.black.withOpacity(0.3),
                        fontSize: 10.sp,
                      ),
                    ),
                    Image.asset(
                      "assets/images/ic_renshu.png",
                      width: 14.w,
                      height: 14.w,
                    ),
                    Text(
                      info.count2.toString(),
                      style: TextStyle(
                        color: Colors.black.withOpacity(0.3),
                        fontSize: 10.sp,
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
        Positioned(
          left: 21.w,
          right: 21.w,
          height: 126.h,
          child: Container(
            decoration: BoxDecoration(
              borderRadius: 7.radius,
              boxShadow: const [Shadows.primaryShadow],
              image: DecorationImage(
                image: AssetImage(info.image),
                fit: BoxFit.cover,
              ),
            ),
          ),
        )
      ]),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Obx(() => SmartRefresher(
          controller: controller.refreshController,
          physics: const BouncingScrollPhysics(),
          footer: const ClassicFooter(
            loadStyle: LoadStyle.ShowWhenLoading,
            completeDuration: Duration(milliseconds: 500),
          ),
          onRefresh: controller.onRefresh,
          child: ListView.separated(
            itemCount: controller.data.length,
            itemBuilder: (context, index) {
              return buildItem(controller.data[index]);
            },
            separatorBuilder: (context, index) {
              return 10.hGap;
            },
          ),
        ));
  }
}
